<template>
  <el-card class="statistics-card">
    <div class="stats-grid">
      <div class="stat-item">
        <div class="stat-label">总模板数</div>
        <div class="stat-value" v-loading="loading">
          {{ statistics.total }}
        </div>
      </div>
      <div class="stat-item">
        <div class="stat-label">启用模板</div>
        <div class="stat-value text-success" v-loading="loading">
          {{ statistics.enabled }}
        </div>
      </div>
      <div class="stat-item">
        <div class="stat-label">禁用模板</div>
        <div class="stat-value text-info" v-loading="loading">
          {{ statistics.disabled }}
        </div>
      </div>
      <div class="stat-item">
        <div class="stat-label">使用资产</div>
        <div class="stat-value" v-loading="loading">
          {{ formatNumber(statistics.usage_count) }}
        </div>
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { defineProps } from "vue";

// 格式化数字显示
const formatNumber = (num) => {
  if (!num) return "0";
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};

// 组件属性
const props = defineProps({
  statistics: {
    type: Object,
    default: () => ({
      total: 0,
      enabled: 0,
      disabled: 0,
      usage_count: 0,
    }),
  },
  loading: {
    type: Boolean,
    default: false,
  },
});
</script>

<style scoped lang="scss">
.statistics-card {
  margin-bottom: 20px;
  border-radius: 8px;
  border: none;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  padding: 10px 0;
}

.stat-item {
  padding: 15px;
  background-color: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease;

  &:hover {
    transform: translateY(-2px);
  }
}

.stat-label {
  color: #86909c;
  font-size: 14px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  color: #1d2129;
}
</style>
